/**
 * @projectName: project02bywdmtz
 * @package: com.cskaoyan.controller
 * @className: AdminBrandController
 * @author: 冉夏
 * @description: TODO
 * @date: 2022/12/29 1:00
 * @version: 1.8
 */

package com.cskaoyan.controller;
import com.cskaoyan.bean.MarketBrand;
import com.cskaoyan.bean.bo.AdminBrandSearchBo;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.service.AdminBrandShowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

@RestController
@RequestMapping("admin/brand")
public class AdminBrandController {
    @Autowired
    AdminBrandShowService brandShowService;
/*
* 查询所有和用户输入字段查询
* */
    @GetMapping("list")
    public BaseRespVo getAllBrandsInfoBySearch(AdminBrandSearchBo adminBrandSearchBo){
        CommonData<MarketBrand> marketBrandCommonData=brandShowService.getBrandInfoByInput(adminBrandSearchBo);
        return BaseRespVo.ok(marketBrandCommonData,"成功");
    }
    /*
    *品牌商的删除  非真正删除  修改状态码 0===>1
    * */
    @PostMapping("delete")
    public BaseRespVo deleteBrand(@RequestBody MarketBrand marketBrand){
        //肯定会删除成功 就不做状态码的校验
        brandShowService.deleteBrandByClick(marketBrand);
        return BaseRespVo.ok(0,"哼!你再删我真的要生气了");
    }
    /*
    * 品牌的信息编辑  根据指定id更新
    *
    * */
    @PostMapping("update")
    public BaseRespVo updateBrand(@RequestBody MarketBrand marketBrand){
        MarketBrand marketBrandUpdate=brandShowService.updateBrandInfo(marketBrand);
        return BaseRespVo.ok(marketBrandUpdate);
    }

    /*
    * 品牌的添加
    * */
    @PostMapping("create")
    public BaseRespVo createBrand(@RequestBody MarketBrand marketBrand){
        BigDecimal floorPrice = marketBrand.getFloorPrice();
        //需要对写入的价格进行判断 是否符合规范
        double floor_price = Double.parseDouble(floorPrice.toString());
        if(floor_price<0){
            return BaseRespVo.invalidData("价格为负,你想干嘛？");
        }
        marketBrand.setDeleted(false);
        MarketBrand marketBrandCreate=brandShowService.creatBrand(marketBrand);
        return BaseRespVo.ok(marketBrandCreate);
    }
}
